<?php

namespace app\common\model;

class OverallConfig extends BaseModel
{
    protected $name = "overall_config";

    /**
     * 获取条件匹配的数据
     * @param array $where 条件
     * @param string $field 字段
     * @param string $sort 排序
     * @return array
     */
    public function getConditionData(array $where = [], string $field = "*", string $sort = "asc"): array
    {
        return $this->field($field)->where($where)->order('sort', $sort)->select()->toArray();
    }

    /**
     * 添加数据
     * @param array $data
     * @return int
     */
    public function addData(array $data): int
    {
        //添加时销毁自带的主键id
        unset($data['id']);
        return $this->save($data);
    }

    /**
     * 更新数据
     * @param array $data
     * @return bool
     */
    public function saveData($id, array $data): bool
    {
        $model = self::find($id);
        return $model->save($data);
    }

    /**
     * 获取一条数据
     * @param array $where 条件
     * @param string $field 字段
     * @return array
     */
    public function getConditionOne(array $where = [], string $field = "*"): array
    {
        return $this->field($field)->where($where)->find()->toArray();
    }
}